﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RayTracerLib;
using System.Xml;
using CommonLib.Engine;
using RayTracerLib.Engine;
using System.IO;
using CommonLib.Common;
namespace Editor
{
    public partial class PresentationForm : Form
    {
        public Scene Scene { get; set; }
        public Engine Engine { get; set; }
        public PresentationForm()
        {
            InitializeComponent();
        }
        public PresentationForm(Scene scn)
        {
            InitializeComponent();
            Scene = scn;
            Engine = new Engine(new Panel() { Width = 500, Height = 500 });
        }
        private void panelSettings_Load(object sender, EventArgs e)
        {
            if (image != null)
                image.Dispose();
            Draw();
        }
        Bitmap image = null;
        private void Draw()
        {
            Settings sett = panelSettings.GetCurrentSettings();
            if (sett.ShadingClass != null)
            {
                Engine.Render(Scene, panelSettings.GetCurrentCamera(), sett,null);
                image = new Bitmap(Path.Combine(Application.StartupPath, "temp.bmp"));
                present_panel.BackgroundImage = image;
            }
            else
                MessageBox.Show("Система не знает ни одного визуализатора");
        }

        private void panelSettings_RefreshImage(object sender, EventArgs e)
        {
            if (image != null)
                image.Dispose();
            Draw();
        }
        private void PresentationForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            Hide();
        }
    }
}
